home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5441 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
  2. From: Dan Pop <danpop@mail.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Limit on #bytes inside of struct?
  5. Date: Sat, 10 Feb 1996 01:53:41 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9602100053.AA09863@dxmint.cern.ch>
  8. References: <4fgg7g$r36@cville-srv.wam.umd.edu>
  9. X-NNTP-Posting-Host: hpl3sn03.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
  12.  
  13. jsquires@wam.umd.edu (jeffrey d squires) writes:
  14.  
  15. >What I left out was that I tried to do this:
  16. >
  17. >#define NUM_PASSES 3
  18. >hist_type histogram[NUM_PASSES];  /* BIIIIIG MISTAKE */
  19.  
  20. ???  I can't see any mistake here.
  21.  
  22. >I tried to have the above example be simple, but it appears that I left
  23. >out the part that contained the problem.  I guess that you can;t
  24. >declare an array with the size defined by #define.  I had to do:
  25.  
  26. Your guess is wrong.
  27.  
  28.     #define NUM_PASSES 3
  29.     hist_type histogram[NUM_PASSES];
  30. and
  31.     hist_type histogram[3];
  32.  
  33. are perfectly equivalent (NUM_PASSES has already been replaced by 3 when
  34. the compiler actually parses the declaration, during translation phase 7).
  35.  
  36. >hist_type * histogram;
  37. >histogram = .... malloc(NUM_PASSES * ......
  38. >
  39. >That worked, and my problem is solved.  Thanks everyone for responding
  40.  
  41. This is a red herring.  The bug is still there, but you can't see its
  42. effect because you changed the memory allocation scheme and 'num' is no
  43. longer right after 'histogram'.
  44.  
  45. Dan
  46. -- 
  47. Dan Pop
  48. CERN, CN Division
  49. Email: danpop@mail.cern.ch 
  50. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  51.